<template>
  <div>
    <el-tag :type="state.type" v-if="renderRow.priority !== null">{{
      state.statusDict[renderField.prop as any][renderRow.priority]
    }}</el-tag>
    <el-tag :type="state.type" v-else-if="renderRow.processState !== null">{{
      state.statusDict[renderField.prop as any][renderRow.processState]
    }}</el-tag>
    <el-tag :type="state.type" v-else-if="renderRow.productType !== null">{{
      state.statusDict[renderField.prop as any][renderRow.productType]
    }}</el-tag>
    <el-tag :type="state.type" v-else-if="renderRow.planState !== null">{{
      state.statusDict[renderField.prop as any][renderRow.planState]
    }}</el-tag>
    <el-tag :type="state.type" v-else-if="renderRow.isSuspend !== null">{{
      state.statusDict[renderField.prop as any][renderRow.isSuspend]
    }}</el-tag>
    <el-tag :type="state.type" v-else-if="renderRow.isProduct !== null">{{
      state.statusDict[renderField.prop as any][renderRow.isProduct]
    }}</el-tag>
    <el-tag :type="state.type" v-else-if="renderRow.otherUnit !== null">{{
      state.statusDict[renderField.prop as any][renderRow.otherUnit]
    }}</el-tag>
    <el-tag :type="state.type" v-else-if="renderRow.state !== null">{{
      state.statusDict[renderField.prop as any][renderRow.state]
    }}</el-tag>
    <el-tag :type="state.type" v-else>{{
      state.statusDict[renderField.prop as any][Number(renderRow.orderStatus)]
    }}</el-tag>
  </div>
</template>
<script lang="ts" setup>
import { ref, onMounted, reactive, inject } from "vue";
import type { TableColumn, TableRow, OptButton } from "@/utils/baTable"; //表格列行类型
import { CollectionTag } from "@element-plus/icons-vue";

const dictionary = inject("dictionary") as any;

// BuildAdmin将自动为此组件传递五个Props
interface Props {
  renderValue: any; // 单元格值
  renderRow: TableRow; // 当前行数据
  renderField: TableColumn; // 当前列数据
}

const props = withDefaults(defineProps<Props>(), {});

const state: { statusDict: anyObj; type: string } = reactive({
  statusDict: dictionary.moreTags,
  type:
    dictionary.moreTags[props.renderField.prop as any][
      props.renderRow.planState
    ] === "已完成" ||
    dictionary.moreTags[props.renderField.prop as any][
      props.renderRow.processState
    ] === "已完成" ||
    dictionary.moreTags[props.renderField.prop as any][
      props.renderRow.isSuspend
    ] === "是" ||
    dictionary.moreTags[props.renderField.prop as any][
      props.renderRow.isProduct
    ] === "是" ||
    dictionary.moreTags[props.renderField.prop as any][
      props.renderRow.otherUnit
    ] === "是"
      ? "success"
      : dictionary.moreTags[props.renderField.prop as any][
          props.renderRow.planState
        ] === "已签收" ||
        dictionary.moreTags[props.renderField.prop as any][
          props.renderRow.processState
        ] === "已签收" ||
        dictionary.moreTags[props.renderField.prop as any][
          props.renderRow.priority
        ] === "低级"
      ? "info"
      : dictionary.moreTags[props.renderField.prop as any][
          props.renderRow.planState
        ] === "加工中" ||
        dictionary.moreTags[props.renderField.prop as any][
          props.renderRow.processState
        ] === "加工中" ||
        dictionary.moreTags[props.renderField.prop as any][
          props.renderRow.orderStatus
        ] === "交易关闭"
      ? "warning"
      : dictionary.moreTags[props.renderField.prop as any][
          props.renderRow.planState
        ] === "已下达" ||
        dictionary.moreTags[props.renderField.prop as any][
          props.renderRow.planState
        ] === "已派工" ||
        dictionary.moreTags[props.renderField.prop as any][
          props.renderRow.processState
        ] === "已下达" ||
        dictionary.moreTags[props.renderField.prop as any][
          props.renderRow.processState
        ] === "已派工" ||
        dictionary.moreTags[props.renderField.prop as any][
          props.renderRow.processState
        ] === "已派工" ||
        dictionary.moreTags[props.renderField.prop as any][
          props.renderRow.priority
        ] === "特级" ||
        dictionary.moreTags[props.renderField.prop as any][
          props.renderRow.priority
        ] === "高级" ||
        dictionary.moreTags[props.renderField.prop as any][
          props.renderRow.priority
        ] === "中级" ||
        dictionary.moreTags[props.renderField.prop as any][
          props.renderRow.productType
        ] === "自制" ||
        dictionary.moreTags[props.renderField.prop as any][
          props.renderRow.productType
        ] === "科研" ||
        dictionary.moreTags[props.renderField.prop as any][
          props.renderRow.productType
        ] === "车体" ||
        dictionary.moreTags[props.renderField.prop as any][
          props.renderRow.productType
        ] === "采购" ||
        dictionary.moreTags[props.renderField.prop as any][
          props.renderRow.productType
        ] === "总装"
      ? ""
      : "danger",
});

onMounted(() => {
  // console.log(
  //   "TagVue单元格值",
  //   dictionary.moreTags,
  //   props.renderRow.state,
  //   props.renderField.prop,
  //   state.statusDict[props.renderField.prop as any][props.renderRow.state]
  // );
});
</script>
<style lang="scss" scoped></style>
